package singleton.lazy;

import java.io.Serializable;

/**
 * 内部类
 * @author lenovo
 *优点：线程安全
 *缺点：反射攻击，序列化反序列化攻击
 */
public class LazyInnerClassSingleton implements Serializable{
	static {
		System.out.println("外部类被加载");
	}
	private LazyInnerClassSingleton() {
		System.out.println("外部类构造方法");
		if (LazyHolder.LAZY!=null) {
			throw new RuntimeException("not null");
		}
	}
	{
		System.out.println("外部类方法块");
	}
	public static final LazyInnerClassSingleton getInstance() {
		System.out.println("getInstance");
		return LazyHolder.LAZY;
	}
	public static class LazyHolder{
		public LazyHolder(){
			System.out.println("内部类构造方法");
		}
		static{
			System.out.println("内部类静态方法");
		}
		{
			System.out.println("内部类方法块");
		}
		private static final LazyInnerClassSingleton LAZY=new LazyInnerClassSingleton();
	}
}
